|
|
|
|
|
|
|
As a general rule, use a snapshot whenever you want a set of data that isn't time sensitive; that is, it doesn't matter whether records in the underlying database are modified after the snapshot is created. The most frequent use of snapshots in a program is to generate reports or informational screens in which the data is static. |
|
|
|
|
|
|
|
|
Advantages of Using Snapshots |
|
|
|
|
|
|
|
|
Snapshots provide you with the following advantages: |
|
|
|
|
|
|
|
|
You can join information from multiple tables. |
|
|
|
|
|
|
|
|
You can use the Find methods to locate records. |
|
|
|
|
|
|
|
|
Record navigation and recordset creation can be faster for a snapshot than for a read-only dynaset because a snapshot is a copy of the data, not a set of pointers to the data. |
|
|
|
|
|
|
|
|
Disadvantages of Using Snapshots |
|
|
|
|
|
|
|
|
The primary disadvantage of using a snapshot is that it is not an updateable recordset. In addition, you can't use an index with a snapshot to help set the order of the data or locate specific records. |
|
|
|
|
CAUTION
|
|
|
|
|
To avoid memory constraints, make sure that a snapshot returns only a small set of records. |
|
|
|
|
|
|
|
|
|
|
You can create a snapshot by defining a Recordset object with the Dim statement and then using the OpenRecordset method with the dbOpenSnapshot parameter to assign the records to the object. As with a dynaset, you can specify optional parameters in the OpenRecordset method. Table 26.3 summarizes these parameters. |
|
|
|
|
| Table 26.3 Options Used to Modify the Access Mode of a Snapshot | | Option | Action | | dbDenyWrite | Prevents others in a multiuser environment from writing to the snapshot while you have it open | | dbForwardOnly | Enables only forward scrolling through the snapshot | | dbSQLPassThrough | Passes the SQL statement used to create the snapshot to an ODBC database to be processed |
|
|
|
|
|
|
Using a Forward-Only Recordset |
|
|
|
|
|
|
|
|
A forward-only recordset is a special type of snapshot that allows only forward scrolling through its records. This means that the MoveFirst, MovePrevious, and Find methods do not work on the recordset. The advantage of using this type of recordset is that it is faster than a snapshot. However, the forward-only recordset should be used only in situations in which a single pass through the recordset is needed, such as in report generation routines. |
|
|
|
|
|
|
|
|
To set up a forward-only recordset, you use the OpenRecordset method and specify the dbOpenForwardOnly constant as shown in the following line of code: |
|
|
|
|
|
|
|
|
Set MyRS = MyDB.OpenRecordset(sSQL, dbOpenForwardOnly) |
|
|
|
|
|